package com.yyhh.helpcall;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import com.yyhh.helpcall.base.RecordConfig;
import com.yyhh.helpcall.utils.NetLog;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import cn.jpush.android.ups.JPushUPSManager;
import cn.jpush.android.ups.TokenResult;
import cn.jpush.android.ups.UPSRegisterCallBack;

public class MainApplication extends Application {

    public static MainApplication mainApplication;
    public static RecordConfig recordConfig = new RecordConfig();

    @Override
    public void onCreate() {
        super.onCreate();
        mainApplication = this;

//        AppKey:
//        7ce2bb3fe5c7029c66f3e0e9
//        Master Secret:
//        e2564d16ecb0877aafeda558
        JPushUPSManager.registerToken(this,"7ce2bb3fe5c7029c66f3e0e9",null,null,new UPSRegisterCallBack(){

            @Override
            public void onResult(TokenResult tokenResult) {
                NetLog.d("registerToken " + tokenResult.toString());
            }
        });

        UMConfigure.init(this, "60c81e9aa82b08615e50dbf0", "Common", UMConfigure.DEVICE_TYPE_PHONE, null);
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);

        createNotificationChannel("commonPush", "常规消息通知", "请开启,该渠道可以正常接受普通的消息推送");
        createNotificationChannel("customerDesc", "来电客户详情", "请开启,该渠道可以根据来电号码显示该客户的历史通话详情数据");
        createForegroundNotificationChannel("foregroundServer", "助融通前台服务", "请开启,该渠道可以根据来电号码显示该客户的历史通话详情数据");
    }

    //设置通知渠道
    private void createNotificationChannel(String channelId, String channelName, String channelDesc) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
            channel.setDescription(channelDesc);
            channel.enableLights(true);
            channel.enableVibration(true);
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(channel);
        }
    }

    //设置前台服务的通知渠道
    private void createForegroundNotificationChannel(String channelId, String channelName, String channelDesc) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
            channel.setDescription(channelDesc);
            channel.enableLights(false);
            channel.enableVibration(false);
            channel.setSound(null, null);
            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(channel);
        }
    }

}
